package com.kafka.study.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.kafka.study.consumer.FilterConsumer;
import com.kafka.study.model.MessageDto;
import com.kafka.study.producer.KafkaProducer;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
public class MessageController {
    @Resource
    private KafkaProducer kafkaProducer;

    @Resource
    private FilterConsumer filterConsumer;

    @PostMapping(path = "/send")
    public String sendMessage(@RequestBody MessageDto dto) throws ParseException, JsonProcessingException {
        kafkaProducer.sendMessage(dto);
        return "Ok";
    }

    @PostMapping(path = "/consume")
    public String consumeMessages() {
        filterConsumer.consume();
        return "OK";
    }
}
